package com.ukao.cashregister.ui.setting;


import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TextView;

import com.ukao.cashregister.R;
import com.ukao.cashregister.base.BaseFragment;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.utils.CheckUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;
import butterknife.Unbinder;

import static com.ukao.cashregister.R.id.paymentPrice;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link CareLabelFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class CareLabelFragment extends BaseFragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.back_tv)
    TextView backTv;
    @BindView(R.id.quit)
    TextView quit;
    @BindView(R.id.rfid_btn)
    RadioButton rfidBtn;
    @BindView(R.id.canvas_btn)
    RadioButton canvasBtn;
    Unbinder unbinder;

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;


    public static CareLabelFragment newInstance(String param1, String param2) {
        CareLabelFragment fragment = new CareLabelFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_care_label, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
    }

    @Override
    protected void initView() {
       if (SaveParamets.isRfidLabel()){
           rfidBtn.setChecked(true);
       }else{
           canvasBtn.setChecked(true);
       }
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }



    @OnCheckedChanged({R.id.canvas_btn, R.id.rfid_btn})
    public void onChekChanged(CompoundButton view, boolean check) {

        if (check) {
            switch (view.getId()) {
                case R.id.canvas_btn:
                    SaveParamets.setRfidLabel(false);
                    setDrawableRight(R.drawable.wifi_induce  ,canvasBtn);
                    setDrawableRight(R.drawable.transparent  ,rfidBtn);
                    break;
                case R.id.rfid_btn:
                    SaveParamets.setRfidLabel(true);
                    setDrawableRight(R.drawable.wifi_induce  ,rfidBtn);
                    setDrawableRight(R.drawable.transparent  ,canvasBtn);
                    break;
            }
        }
    }

    private void setDrawableRight(int id,  RadioButton  mRadioButton) {
        Drawable drawable = getResources().getDrawable(id);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        mRadioButton.setCompoundDrawables(null, null, drawable, null);
    }

    @OnClick({R.id.back_tv, R.id.quit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_tv:
                finish();
                break;
            case R.id.quit:
                break;
        }
    }
}
